<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="../inc.jsp"></jsp:include>
<script type="text/javascript" charset="utf-8">
	var datagrid;
	var index = 0;
	$(function() {

		datagrid = $('#datagrid').datagrid({
			url : 'query.do',
			title : '商户列表',
			iconCls : 'icon-save',
			pagination : true,
			pagePosition : 'bottom',
			pageSize : 10,
			pageList : [ 20, 30, 40, 50 ],
			fit : true,
			fitColumns : false,
			nowrap : false,
			border : false,
			idField : 'storeId',
			sortName : 'storeName',
			sortOrder : 'desc',
			checkOnSelect : true,
			selectOnCheck : true,
			frozenColumns : [ [ {
				title : '编号',
				field : 'storeId',
				width : 150,
				sortable : true,
				checkbox : true
			}, {
				title : '商铺名称',
				field : 'storeName',
				width : 150,
				sortable : true
			} ] ],
			columns : [ [ {
				title : '地址',
				field : 'address',
				width : 100
			}, {
				title : '联系电话',
				field : 'telephone',
				sortable : true,
				width : 150
			}, {
				title : '点击数',
				field : 'storeClick',
				sortable : true,
				width : 150
			}, {
				title : '评论数',
				field : 'commentCount',
				width : 150,
				hidden : true
			}, {
				title : '人均消费',
				field : 'personConsume',
				width : 150
			}, {
				title : '状态',
				field : 'isAppointment',
				width : 150,
				formatter : function(value, rowData, rowIndex) {
					return value == 1 ? '开启' : '关闭';
				}
			}, {
				title : '审核',
				field : 'isAudit',
				width : 150,
				formatter : function(value, rowData, rowIndex) {
					var show;
					if (value == 1)
						show = "待审核";
					else if (value == 2)
						show = "审核通过";
					else if (value == 3)
						show = "审核未通过";
					return show;
				}
			} ] ],
			toolbar : [ {
				text : '增加',
				iconCls : 'icon-add',
				handler : function() {
					add();
				}
			}, '-', {
				text : '删除',
				iconCls : 'icon-remove',
				handler : function() {
					remove();
				}
			}, '-', {
				text : '修改',
				iconCls : 'icon-edit',
				handler : function() {
					edit();
				}
			}, '-', {
				text : '取消选中',
				iconCls : 'icon-undo',
				handler : function() {
					datagrid.datagrid('clearSelections');
					datagrid.datagrid('unselectAll');
				}
			}, '-' ],
			onRowContextMenu : function(e, rowIndex, rowData) {
				e.preventDefault();
				$(this).datagrid('unselectAll');
				$(this).datagrid('selectRow', rowIndex);
				$('#menu').menu('show', {
					left : e.pageX,
					top : e.pageY
				});
			}
		});

	});
	function add() {
		var p = parent.sy.dialog({
			title : '添加商户',
			href : 'store/add.do',
			width : 500,
			height : 200,
			buttons : [ {
				text : '添加',
				handler : function() {
					var f = p.find('form');
					f.form('submit', {
						url : 'store/save.do',
						success : function(data) {
							datagrid.datagrid('reload');
							p.dialog('close');
							parent.sy.messagerShow({
								msg : "添加成功！",
								title : '提示'
							});
						}
					});
				}
			} ]
		});
	}
	function remove() {
		var rows = datagrid.datagrid('getChecked');
		var ids = [];
		if (rows.length > 0) {
			parent.sy.messagerConfirm('请确认', '您要删除当前所选项目？', function(r) {
				if (r) {
					for ( var i = 0; i < rows.length; i++) {
						ids.push(rows[i].storeId);
					}
					$.ajax({
						type: 'POST',
						url : 'delete.do',
						data : {
							ids : ids.join(',')
						},
						dataType : 'json',
						success : function(d) {
							datagrid.datagrid('load');
							datagrid.datagrid('unselectAll');
							parent.sy.messagerShow({
								title : '提示',
								msg : "删除成功！"
							});
						}
					});
				}
			});
		} else {
			parent.sy.messagerAlert('提示', '请勾选要删除的记录！', 'error');
		}
	}
	function _search() {
		datagrid.datagrid('load', sy.serializeObject($('#searchForm')));
	}
	function cleanSearch() {
		datagrid.datagrid('load', {});
		$('#searchForm input').val('');
	}
</script>
</head>
<body class="easyui-layout" data-options="fit:true">
	<div data-options="region:'north',border:false,title:'过滤条件'"
		style="height: 58px; overflow: hidden;" align="left">
		<form id="searchForm">
			<table class="tableForm datagrid-toolbar"
				style="width: 100%; height: 100%;">
				<tr>
					<th width='100px'>商户名称</th>
					<td width='150px'><input name="storeName" /></td>
					<th width='80px'>审核</th>
					<td width='100px'><select class="easyui-combobox" name="audit"
						editable="false">
							<option value="">请选择...</option>
							<option value="1">待审核</option>
							<option value="2">审核通过</option>
							<option value="3">审核未通过</option>
					</select></td>
					<td><a href="javascript:void(0);" class="easyui-linkbutton"
						onclick="_search();">过滤</a><a href="javascript:void(0);"
						class="easyui-linkbutton" onclick="cleanSearch();">取消</a></td>
				</tr>
			</table>
		</form>
	</div>
	<div data-options="region:'center',border:false"
		style="overflow: hidden;">
		<table id="datagrid"></table>
	</div>

	<div id="menu" class="easyui-menu" style="width: 120px; display: none;">
		<div onclick="append();" data-options="iconCls:'icon-add'">增加</div>
		<div onclick="remove();" data-options="iconCls:'icon-remove'">删除</div>
		<div onclick="edit();" data-options="iconCls:'icon-edit'">编辑</div>
	</div>
</body>
</html>